package com.letv.whatslive.model.convert;

import com.letv.whatslive.common.utils.ObjectUtils;
import com.letv.whatslive.model.DoubleLiveLog;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by wangjian7 on 2016/1/28.
 */
public class DoubleLiveLogConvert {

    public static DBObject castDoubleLiveLogToDBObject(DoubleLiveLog doubleLiveLog) {
        DBObject dbo = new BasicDBObject();
        if (doubleLiveLog.getId() != null) {
            dbo.put("_id", doubleLiveLog.getId());
        }
        dbo.put("uid",doubleLiveLog.getUid());
        dbo.put("inviteUid",doubleLiveLog.getInviteUid());
        dbo.put("pId",doubleLiveLog.getPId());
        dbo.put("action",doubleLiveLog.getAction());
        dbo.put("retryNum",doubleLiveLog.getRetryNum());
        dbo.put("status",doubleLiveLog.getStatus());
        if(null!=doubleLiveLog.getReason()){
            dbo.put("reason", doubleLiveLog.getReason());
        }
        dbo.put("date", doubleLiveLog.getDate());
        return dbo;
    }

    public static DoubleLiveLog castDBObjectToDoubleLiveLog(DBObject dbObject) {
        DoubleLiveLog doubleLiveLog = new DoubleLiveLog();
        if(dbObject != null) {
            doubleLiveLog.setId(ObjectUtils.toLong(dbObject.get("_id")));
            doubleLiveLog.setUid(ObjectUtils.toString(dbObject.get("uid"), ""));
            doubleLiveLog.setInviteUid(ObjectUtils.toString(dbObject.get("inviteUid"), ""));
            doubleLiveLog.setPId(ObjectUtils.toString(dbObject.get("pId"), ""));
            doubleLiveLog.setAction(ObjectUtils.toInteger(dbObject.get("action")));
            doubleLiveLog.setRetryNum(ObjectUtils.toInteger(dbObject.get("retryNum")));
            doubleLiveLog.setStatus(ObjectUtils.toInteger(dbObject.get("status")));
            doubleLiveLog.setReason(ObjectUtils.toString(dbObject.get("reason"),""));
            doubleLiveLog.setDate(ObjectUtils.toLong(dbObject.get("date")));
            return doubleLiveLog;
        }else{
            return null;
        }
    }
}
